#!/bin/bash
#if [ "$1" == "" ] && [ "$1" -ne "200" ] &&[ "$1" -ne "500" ]
#  then
#  echo "print input 200(4k) or 500(32k)" 
#  exit 1
#else
#  case1 $1
#fi

case1() {
   rm -f tmp.txt
   rm -f tmp_vm.txt
   source /root/admin-openrc
   cinder list |awk '{print $2,$8}' |grep ${1} |awk '{print $1}'  > tmp.txt
   nova list |awk '{ print $2}' |sed -n 4,'$p'  > tmp_vm.txt
   vm_num=`cat tmp_vm.txt |wc -l`
   vm_num=$((vm_list-1))
   volume_num=`cat tmp.txt |wc -l`
   for ((i=1;i<=$volume_num;i++));
   do
   echo $i
   volume_uuid=`sed -n ${i}p tmp.txt`
   echo $volume_uuid
   vm_uuid=`sed -n ${i}p tmp_vm.txt`
   echo $vm_uuid
   nova volume-attach ${vm_uuid}  ${volume_uuid}
   done
}

if [ "$1" == 200 ]  || [ "$1" == 500 ];then
  case1 $1
else
  echo "print input 200(4k) or 500(32k)" 
  exit 1
fi
